package com.mhb.servlet;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.mhb.domain.Employee;
import com.mhb.service.EmployeeService;

/**
 * Servlet implementation class DeleteEmployeeServlet
 */
@WebServlet("/DeleteEmployeeServlet")
public class DeleteEmployeeServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
 
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		System.out.println("delete");
		String id= request.getParameter("id");
		
		EmployeeService employeeService=new EmployeeService();
		try {
			employeeService.deleteEmployeeById(Integer.valueOf(id));
			List<Employee> employeeList = employeeService.getEmployee();
			request.setAttribute("employeeList", employeeList);
	   /*		response.sendRedirect(request.getContextPath()+"/main.jsp");*/
			request.getRequestDispatcher("/main.jsp").forward(request, response);
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}


}
